import { bindCustomEditing, equalsN3, ESGltfModel, ESJEditingMode, ESSceneObject } from "earthsdk3";
import { PartialWithUndefinedReactivePropsToNativeProps, ReactivePropsToNativePropsAndChanged, SceneObjectKey, extendClassProps } from "earthsdk3";

/**
 *  ESForest使用的模型
 */
export class ESFeTreeAdding extends ESGltfModel {
    static override readonly type = this.register('ESFeTreeAdding', this, { chsName: 'ESForest使用的模型', tags: ['ESObjects', '_ES_Impl_Cesium', '_ES_Impl_UE'], description: "地理多边形体" });
    override get typeName() { return 'ESFeTreeAdding'; }
    override get defaultProps() { return ESFeTreeAdding.createDefaultProps(); }
    override get json() {
        return {
            // @ts-ignore
            ...this._innerGetJson(),
            "rotation": this.rotation,
        } as JsonType;
    }
    override set json(value: JsonType) { this._innerSetJson(value); }

    public override combinationClass: boolean = true;
    public override getMainClass(): ESSceneObject { return this.mainClass ?? this }
    constructor(id?: SceneObjectKey) {
        super(id);
        const updateEditing = () => {
            if (this.positionEditing) {
                const editingModes: string[] = [];
                if (!this.position || equalsN3(this.position, [0, 0, 0])) {
                    editingModes.push(ESJEditingMode.Place);
                }
                editingModes.push(ESJEditingMode.Translation, ESJEditingMode.Rotation);
                this.activeViewer?.startEditing(this, editingModes);
            }
        }
        bindCustomEditing(this, updateEditing.bind(this), 'positionEditing');
    }
    override getESProperties() {
        const properties = { ...super.getESProperties() };
        return {
            ...properties,
            coordinate: [
                ...properties.coordinate,
            ]
        };
    };
    override getProperties(language: string) {
        return [
            ...super.getProperties(language),
        ];
    }
}

export namespace ESFeTreeAdding {
    export const createDefaultProps = () => ({
        ...ESGltfModel.createDefaultProps(),
        treeModelClassName: undefined as string | undefined,
        shugao: undefined as number | undefined,
        xiongjing: undefined as number | undefined,
        zhixiagao: undefined as number | undefined,
        dongxiguanfu: undefined as number | undefined,
        nanbeiguanfu: undefined as number | undefined,
        plotId: undefined as string | undefined,
        time: undefined as string | undefined,
        positionEditing: false as boolean | undefined, //编辑位置
    });
}
extendClassProps(ESFeTreeAdding.prototype, ESFeTreeAdding.createDefaultProps);
export interface ESFeTreeAdding extends ReactivePropsToNativePropsAndChanged<ReturnType<typeof ESFeTreeAdding.createDefaultProps>> { }
type JsonType = PartialWithUndefinedReactivePropsToNativeProps<ReturnType<typeof ESFeTreeAdding.createDefaultProps> & { type: string }>;